#ifndef __PASSTHROUGH_IO_MAP__
#define __PASSTHROUGH_IO_MAP__

#include <VBox/vmm/pdmdev.h>
#include <VBox/vmm/pdmnetifs.h>
#include <iprt/asm.h>
#include <iprt/assert.h>
#ifdef IN_RING3
#include <iprt/mem.h>
#include <iprt/uuid.h>
#include <iprt/semaphore.h>
#include <iprt/thread.h>
#endif /* IN_RING3 */
#include "Virtio.h"
#include <io.h>
#include <windows.h>



typedef struct tagMyState
{
	/* VPCISTATE must be the first member! */
	VPCISTATE VPCI;
	R3PTRTYPE(PVQUEUE) pRxQueue;
	R3PTRTYPE(PVQUEUE) pTxQueue;
	R3PTRTYPE(PVQUEUE) pCtlQueue;
    R3PTRTYPE(PPDMINETWORKUP) pDrv;
	RTTHREAD WriteThread;
	RTSEMEVENT EventWrite;
} MyState;

typedef MyState *PMyState;

enum
{
	VIRTIO_WRITE = 0x10,
	VIRTIO_READ = 0x11,
	VIRTIO_OPEN = 0x12,
	VIRTIO_RELEASE = 0x13
};

typedef struct __virtio_hdr
{
	int connection_id;			//which pipe
	unsigned int operator_code; // write - 0x10 / read - 0x11  / open - 0x12 / release - 0x13
	int wanted_size;			//the size that want to write or read
} virtio_hdr;

typedef struct __virtio_ack
{
	int connection_id; //only used for VIRTIO_OPEN
	int sucessful;	 //success 0, fail -1
	int reserved;	  //always 0
	int done_size;	 //used for VIRTIO_WRITE / VIRTIO_READ
} virtio_ack;

#define REQUEST_HDR_LEN (sizeof(virtio_hdr))
#define REQUEST_ACK_LEN (sizeof(virtio_ack))

typedef struct __virtio_request
{
	virtio_hdr hdr;
	virtio_ack ack;
	char data[1]; //payload;
} virtio_request;

/**
 * @callback_method_impl{FNIOMIOPORTIN}
 */
//pt == pass through
int ptIOPortIn(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t *pu32, unsigned cb);

/**
 * @callback_method_impl{FNIOMIOPORTOUT}
 */
int ptIOPortOut(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t u32, unsigned cb);

#endif
